package co.yixiang.yshop.module.shop.dal.mysql.canvas;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.module.shop.controller.admin.canvas.vo.CanvasExportReqVO;
import co.yixiang.yshop.module.shop.controller.admin.canvas.vo.CanvasPageReqVO;
import co.yixiang.yshop.module.shop.dal.dataobject.canvas.CanvasDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Arrays;
import java.util.List;

/**
 * 画布信息 Mapper
 *
 * @author moxiangrong
 */
@Mapper
public interface CanvasMapper extends BaseMapperX<CanvasDO> {

    default PageResult<CanvasDO> selectPage(CanvasPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CanvasDO>()
                .likeIfPresent(CanvasDO::getName, reqVO.getName())
                .eqIfPresent(CanvasDO::getState, reqVO.getState())
                .eqIfPresent(CanvasDO::getType, reqVO.getType())
                .eqIfPresent(CanvasDO::getIsIndex, reqVO.getIsIndex())
                .betweenIfPresent(CanvasDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(Arrays.asList(CanvasDO::getIsIndex, CanvasDO::getUpdateTime))
        );
    }

    default List<CanvasDO> selectList(CanvasExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CanvasDO>()
                .likeIfPresent(CanvasDO::getName, reqVO.getName())
                .eqIfPresent(CanvasDO::getState, reqVO.getState())
                .betweenIfPresent(CanvasDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CanvasDO::getId));
    }

}
